BEGIN
	DECLARE @id int;
	DECLARE @totalpartnergrantfunds numeric(15,2);
	DECLARE projectcursor  cursor for SELECT id FROM project p
		WHERE (partnergrantfunds IS NULL OR partnergrantfunds = 0)
		AND EXISTS (SELECT 1 FROM project p1 WHERE p1.parentprojectid = p.id);
	open projectcursor
	fetch next from projectcursor into @id;
	while @@FETCH_STATUS = 0
	BEGIN
	SELECT @totalpartnergrantfunds = SUM(ISNULL(partnergrantfunds, 0)) FROM project WHERE parentprojectid = @id;
	IF @totalpartnergrantfunds > 0
		UPDATE project SET partnergrantfunds = @totalpartnergrantfunds WHERE id = @id;
	fetch next from projectcursor into @id;
	END;
	close projectcursor;
	deallocate projectcursor;

END;


GO